//package com.jackstraw.jack_base.rules.service.impl;
//
//import com.hundsun.bontal.rules.common.exception.RulesException;
//import com.hundsun.bontal.rules.dao.RuleGroupDAO;
//import com.hundsun.bontal.rules.dao.RuleGroupGlobalDAO;
//import com.hundsun.bontal.rules.dao.RuleGroupImportDAO;
//import com.hundsun.bontal.rules.dao.RuleMainDAO;
//import com.hundsun.bontal.rules.entity.RuleGroupDO;
//import com.hundsun.bontal.rules.entity.RuleGroupGlobalDO;
//import com.hundsun.bontal.rules.entity.RuleGroupGlobalDOExample;
//import com.hundsun.bontal.rules.entity.RuleGroupImportDO;
//import com.hundsun.bontal.rules.entity.RuleGroupImportDOExample;
//import com.hundsun.bontal.rules.entity.RuleMainDO;
//import com.hundsun.bontal.rules.entity.RuleMainDOExample;
//import com.hundsun.bontal.rules.entity.base.ResultEnum;
//import com.hundsun.bontal.rules.entity.bo.RuleGroupBO;
//import com.hundsun.bontal.rules.entity.bo.RuleGroupGlobalBO;
//import com.hundsun.bontal.rules.entity.bo.RuleGroupImportBO;
//import com.hundsun.bontal.rules.entity.bo.RuleMainBO;
//import com.hundsun.bontal.rules.entity.mapstruct.RuleGroupGlobalMapstruct;
//import com.hundsun.bontal.rules.entity.mapstruct.RuleGroupImportMapstruct;
//import com.hundsun.bontal.rules.entity.mapstruct.RuleGroupMapstruct;
//import com.hundsun.bontal.rules.entity.mapstruct.RuleMainMapstruct;
//import com.hundsun.bontal.rules.service.GroupService;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang3.ObjectUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
//import java.util.Comparator;
//import java.util.List;
//import java.util.Objects;
//import java.util.stream.Collectors;
//
//
//@Slf4j
//@Service
//public class GroupServiceImpl implements GroupService {
//    @Autowired
//    private RuleMainDAO ruleMainDAO;
//
//    @Autowired
//    private RuleGroupDAO ruleGroupDAO;
//
//    @Autowired
//    private RuleGroupGlobalDAO ruleGroupGlobalDAO;
//
//    @Autowired
//    private RuleGroupImportDAO ruleGroupImportDAO;
//
//    @Autowired
//    private RuleMainMapstruct ruleMainMapstruct;
//
//    @Autowired
//    private RuleGroupMapstruct ruleGroupMapstruct;
//
//    @Autowired
//    private RuleGroupGlobalMapstruct ruleGroupGlobalMapstruct;
//
//    @Autowired
//    private RuleGroupImportMapstruct ruleGroupImportMapstruct;
//
//
//    @Override
//    public RuleGroupBO queryOne(String groupId) {
//        RuleGroupDO ruleGroupDO = ruleGroupDAO.selectByPrimaryKey(groupId);
//        if (ObjectUtils.isEmpty(ruleGroupDO)) {
//            throw new RulesException(ResultEnum.GROUP_DATA_NO_FIND_BY_DATABASE);
//        }
//
//        if (Objects.equals(0, ruleGroupDO.getIsEffect())) {
//            throw new RulesException(ResultEnum.GROUP_DATA_LOSE_EFFICACY);
//        }
//
//        RuleGroupBO ruleGroupBO = ruleGroupMapstruct.bo(ruleGroupDO);
//
//        return ruleGroupBO;
//    }
//
//    @Override
//    public RuleGroupBO queryOneAll(String groupId) {
//        RuleGroupBO ruleGroupBO = this.queryOne(groupId);
//
//        List<RuleGroupImportBO> ruleGroupImportBOS = this.queryImportSByGroupId(groupId);
//
//        List<RuleMainBO> ruleMainBOS = this.queryRuleMainSByGroupId(groupId);
//
//        List<RuleGroupGlobalBO> ruleGroupGlobalBOS = this.queryGlobalSByGroupId(groupId);
//        ruleGroupBO.setRuleGroupImportBOs(ruleGroupImportBOS);
//        ruleGroupBO.setRuleGroupGlobalBOs(ruleGroupGlobalBOS);
//        ruleGroupBO.setRuleMainBOs(ruleMainBOS);
//        return ruleGroupBO;
//    }
//
//    @Override
//    public Integer queryGroupVersion(String groupId) {
//        try {
//            RuleGroupBO ruleGroupBO = this.queryOne(groupId);
//            return ruleGroupBO.getGroupVersion();
//        } catch (RulesException rulesException) {
//            if (ResultEnum.GROUP_DATA_NO_FIND_BY_DATABASE.getCode().equals(rulesException.getErrorCode())) {
//                return -1;
//            }
//            if (ResultEnum.GROUP_DATA_LOSE_EFFICACY.getCode().equals(rulesException.getErrorCode())) {
//                return -2;
//            }
//        }
//        return 0;
//    }
//
//    @Override
//    public List<RuleGroupImportBO> queryImportSByGroupId(String groupId) {
//        RuleGroupImportDOExample ruleGroupImportDOExample = new RuleGroupImportDOExample();
//        ruleGroupImportDOExample.createCriteria().andGroupIdEqualTo(groupId);
//        List<RuleGroupImportDO> ruleGroupImportDOS
//                = ruleGroupImportDAO.selectByExample(ruleGroupImportDOExample);
//
//        List<RuleGroupImportBO> ruleGroupImportBOS
//                = ruleGroupImportMapstruct.boToS(ruleGroupImportDOS)
//                .stream()
//                .sorted(Comparator.comparing(RuleGroupImportBO::getSort))
//                .collect(Collectors.toList());
//        return ruleGroupImportBOS;
//    }
//
//    @Override
//    public List<RuleGroupGlobalBO> queryGlobalSByGroupId(String groupId) {
//        RuleGroupGlobalDOExample ruleGroupGlobalDOExample = new RuleGroupGlobalDOExample();
//        ruleGroupGlobalDOExample.createCriteria().andGroupIdEqualTo(groupId);
//        List<RuleGroupGlobalDO> ruleGroupGlobalDOS
//                = ruleGroupGlobalDAO.selectByExample(ruleGroupGlobalDOExample);
//
//        List<RuleGroupGlobalBO> ruleGroupGlobalBOS
//                = ruleGroupGlobalMapstruct.boToS(ruleGroupGlobalDOS)
//                .stream()
//                .sorted(Comparator.comparing(RuleGroupGlobalBO::getSort))
//                .collect(Collectors.toList());
//        return ruleGroupGlobalBOS;
//    }
//
//    @Override
//    public List<RuleMainBO> queryRuleMainSByGroupId(String groupId) {
//        RuleMainDOExample ruleMainDOExample = new RuleMainDOExample();
//        ruleMainDOExample.createCriteria()
//                .andGroupIdEqualTo(groupId)
//                .andIsEffectEqualTo(1);
//        List<RuleMainDO> ruleMainDOS
//                = ruleMainDAO.selectByExample(ruleMainDOExample);
//
//        List<RuleMainBO> ruleMainBOS
//                = ruleMainMapstruct.boToS(ruleMainDOS)
//                .stream()
//                .sorted(Comparator.comparing(RuleMainBO::getSort))
//                .collect(Collectors.toList());
//        return ruleMainBOS;
//    }
//}
